package com.demo.designmode.memento.black_box;

import com.demo.designmode.memento.black_box.GameRole;
import com.demo.designmode.memento.black_box.RoleStateCaretaker;

/**
 * @Author: jxm
 * @Description: 备忘录 白箱”备忘录模式 测试
 * @Date: 2023-12-13 11:05
 * @Version: 1.0
 */
public class Client {
    public static void main(String[] args) {
        System.out.println("------------大战Boss前------------");
        //创建角色对象
        GameRole gameRole = new GameRole();
        gameRole.initState();//初始化
        gameRole.stateDisplay();

        //将游戏角色内部状态进行备份
        //创建管理者
        RoleStateCaretaker roleStateCaretaker = new RoleStateCaretaker();
        roleStateCaretaker.setMemento(gameRole.saveState());

        System.out.println("------------大战Boss后------------");
        //大战Boss时，损耗严重
        gameRole.fight();
        gameRole.stateDisplay();

        System.out.println("------------恢复之前状态------------");
        gameRole.recoverState(roleStateCaretaker.getMemento());
        gameRole.stateDisplay();
    }

}
